package com.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dao.DepDao;
import com.entity.Dep;
import com.service.IDepService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@SuppressWarnings("ALL")
@Service
public class DepServiceImpl  implements IDepService {


    @Autowired
    private DepDao depDao;

    public int addDep(Dep dep){
        return depDao.insert(dep);
    }

    @Override
    public IPage searchDep(int page, int limit, Integer depId, String depName){
        Page serach=new Page(page,limit);
        QueryWrapper q=new QueryWrapper();
        if (depId!=null){
            q.eq("depId",depId);
        }
        if (depName!=null){
            q.like("depName",depName);
            System.out.println(depName);

        }
        IPage result=depDao.selectPage(serach,q);
        return result;
    }

    public Dep findById(Integer depId){
        return depDao.selectById(depId);
    }

    public boolean save(Dep dep) {
        int insert = depDao.insert(dep);
        if (insert==0){
            return false;
        }
        return true;
    }

    public boolean updateById(Dep dep) {

        int i = depDao.updateById(dep);
        if (i==0){
            return false;
        }
        return true;
    }


    public boolean removeById(String depId){
        int n =depDao.deleteById(depId);
        if (n!=0){
            return true;
        }
        else{
            return false;
        }
    }




}
